Sample Programs > Sample Codes (Visual C++ 6.0)
Sample Programs
Sample Code (Visual C++ 6.0)
The samples given in this section assumes Microsoft Visual C++ 6.0 for the development platform and VISA library (VISA C API) for the I/O library.
For the VISA library, "KI-VISA Library (3.0.x or later)" can be downloaded from KIKUSUI Website, or NI-VISA by National Instruments (VER. 3.0 or later, VER. 3.2 or later for Windows 2000 or Windows XP) or Agilent VISA (Agilent I/O Library VER M01.00 or later) by Agilent Technologies can be used.
Note that USB functions cannot be used on older versions of VISA. In addition, USB functions cannot be used on Windows 95 or Windows NT 3.5x or 4.0.
Opening a VISA session and setting communication parameters
The next code is a common section to all sample programs that are introduced later. It must be run before starting the communication with the PCR-M.
The format of the VISA resource string that is substituted in the variable pVisaAddress varies for GPIB, RS232C, and USB.
For the GPIB, device address of 5 is assumed.
For the RS232C, the following communication parameters are assumed: 19 200 bps, 8-bit data length, 1-bit stop bit, parity none, and XON/XOFF flow control. Set the PCR-M interface to match these values.
For the USB, there are no interface parameters that need to be set on the PCR-M, but the USB VID (vendor ID), PID (product ID), and serial number must be specified explicitly in the VISA resource string. The VID and PID values can be verified also on the configuration setting display of the PCR-M. The serial number can be verified on the PCR-M rear panel.
The serial number used in the sample below is an example.
ViSession viRM; 'Resource Manager handle
ViSession vi; 'VISA IO Session handle
ViStatus vs; 'Error Status
LPCSTR pVisaAddress = "GPIB0::5::INSTR";
'LPCSTR pVisaAddress = "ASRL1::INSTR";
'LPCSTR pVisaAddress = "USB0::0x0B3E::0x1009::AB123456::INSTR";
vs = viOpenDefaultRM( &viRM);
vs = viOpen( viRM, (ViRsrc)pVisaAddress, VI_NO_LOCK, 0, &vi);
short iIntfType;
vs = viGetAttribute( vi, VI_ATTR_INTF_TYPE, &iIntfType);
switch( iIntfType) {
case 4: 'RS232
vs = viSetAttribute( vi, VI_ATTR_ASRL_BAUD, 19200);
vs = viSetAttribute( vi, VI_ATTR_ASRL_DATA_BITS, 8);
vs = viSetAttribute( vi, VI_ATTR_ASRL_PARITY, VI_ASRL_PAR_NONE);
vs = viSetAttribute( vi, VI_ATTR_ASRL_STOP_BITS, VI_ASRL_STOP_ONE);
vs = viSetAttribute( vi, VI_ATTR_ASRL_FLOW_CNTRL, VI_ASRL_FLOW_XON_XOFF);
vs = viSetAttribute( vi, VI_ATTR_ASRL_END_OUT, VI_ASRL_END_TERMCHAR);
vs = viSetAttribute( vi, VI_ATTR_ASRL_END_IN, VI_ASRL_END_TERMCHAR);
vs = viSetAttribute( vi, VI_ATTR_IO_PROT, VI_PROT_4882_STRS);
vs = viPrintf( vi, ":SYST:REM\n");
break;
case 7: 'USB
vs = viPrintf( vi, ":SYST:REM\n");
break;
}
vs = viSetAttribute( vi, VI_ATTR_TMO_VALUE, 3000);
vs = viSetAttribute( vi, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
vs = viSetAttribute( vi, VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
vs = viClose( vi);
vs = viClose( viRM);